<template>
  <div>
    <a-modal
      v-model="showDlg"
      title="引入属性"
      ok-text="确认"
      cancel-text="取消"
    >
      <a-select v-model="curModelID" @change="onSelected" style="width:60%">
        <a-select-option v-for="(item, index) in tmodels" :key="index" :value="item.uid">{{
          item.s_name
        }}</a-select-option>
      </a-select>
      <a-button @click="onSelected" :disabled="!curModelID">打开物模型</a-button>
      <props-selector-dlg
        ref="propertyListDlg"
        :properties="properties"
      ></props-selector-dlg>
    </a-modal>
  </div>
</template>
<script>
import PropsSelectorDlg from "@/components/cfg/PropsSelectorDlg.vue";
export default {
  components:{
    PropsSelectorDlg
  },
  data() {
    return {
      curModelID: null,
      properties: [],
      showDlg: false,
      callback: null,
      owner: null,
    };
  },
  computed:{
    tmodels() {
      return this.$store.state.tmodel.tmodels;
    },
  },
  methods: {
    Show(callback, owner) {
      this.callback = callback;
      this.owner = owner;
      this.showDlg = true;
    },
    onSelected() {
      if (this.curModelID) {
        let curModel = this.$store.state.tmodel.tmodelCache[this.curModelID]
        if(typeof curModel.body == 'string'){
          let body = JSON.parse(curModel.body)
          if(body){
            this.properties = body.properties
          }
        }else{
          this.properties = curModel.body.properties
        }
        let self = this
        this.$refs.propertyListDlg.Show((index, sel) => {
          console.log("**************", index, sel);
          self.properties = sel
          self.OK()
        });
      }
    },
    OK() {
      if (this.callback) {
        this.callback(this.properties,this.owner);
        this.showDlg = false
      }
    },
  },
};
</script>